﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 迭代器yield : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Threading.Tasks.Task<string> a;
      

        var dd = System.Linq.Enumerable.Range(1, 20).ToList();

        var result = Get(dd);
        while( result.MoveNext())
        {
            Response.Write(result.Current+"<br/>");

        }
    }
    //参见 http://msdn.microsoft.com/zh-cn/library/9k7k7cf0(v=vs.80).aspx
    /// <summary>
    /// 大于5 的 迭代器
    /// </summary>
    /// <param name="array"></param>
    /// <returns></returns>
    IEnumerator<int> Get(IEnumerable<int> array)
    {
        foreach (int a in array)
        {
            if (a > 5) yield return a;
        }
    }
}